<?php

/**
 * comment actions.
 *
 * @package    jiazhang
 * @subpackage comment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class commentActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
        $dql = Doctrine::getTable('ArticleComment')->createQuery()->orderBy('created_at desc');
        $page = $request->getParameter('page',1);
        $this->pager = new sfDoctrinePager('ArticleComment',30);
        $this->pager->setQuery($dql);
        $this->pager->setPage($page);
        $this->pager->init();
  }
  
  public function executeShow(sfWebRequest $request){
      $id = (int)$request->getParameter('id',0);
      $this->forward404Unless($this->comment = Doctrine::getTable('ArticleComment')->findOneById($id));
  }
  
    public function executeChange_comment_display(sfWebRequest $request){
       $display = (int)$request->getParameter('display',1);
       $id = (int)$request->getParameter('id',0);
       $this->forward404Unless($comment = Doctrine::getTable('ArticleComment')->findOneById($id));
       $comment->setDisplay($display)->save();
       $this->getUser()->setFlash('success', '数据更新成功！');
       $this->redirect('comment/index');
  }
  
  public function executeRecommend(sfWebRequest $request){
       $recommend = (int)$request->getParameter('recommend',1);
       $id = (int)$request->getParameter('id',0);
       $this->forward404Unless($comment = Doctrine::getTable('ArticleComment')->findOneById($id));
       $comment->setRecommend($recommend)->setRecommendTime(time())->save();
       $this->getUser()->setFlash('success', '数据更新成功！');
       $this->redirect('comment/index');
  }
  
}
